<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use fast\WeChat AS EasyWeChat;

class Wx extends Frontend
{

    protected $model = null;
    protected $wx = null;
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();


        $this->model = model('User');
        $this->wx = (new EasyWeChat())->getApp();
    }

    public function msg()
    {
        $this->wx->server->setMessageHandler(function ($message) {
            if ($message->MsgType == 'event') {
                switch ($message->Event) {
                    case 'scancode_waitmsg':
                        if ($message->EventKey == '6144896463') {
                            return $this->scan($message->FromUserName, $message->ScanCodeInfo['ScanResult']);
                            return $message->ScanCodeInfo['ScanResult'];
                        }
                        break;
                    default:
                        return '开发中!';
                        break;
                }
            }
            return '开发中 !';
        });
        $server = $this->wx->server->serve();
        return $server->send();
    }

}
